package service.impl;

import entity.ResearchProjects;
import mapper.ResearchProjectsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import service.ResearchProjectsService;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class ResearchProjectsImpl implements ResearchProjectsService {
    @Autowired private ResearchProjectsMapper mapper;
    public ResearchProjects getById(Integer id) { return mapper.selectById(id); }
    public List<ResearchProjects> getAll() { return mapper.selectAll(); }
    public List<ResearchProjects> getByStudentId(Integer sid) { return mapper.selectByStudentId(sid); }
    public int create(ResearchProjects p) {
        p.setCreatedAt(LocalDateTime.now());
        p.setUpdatedAt(LocalDateTime.now());
        // 确保score字段不为null
        if (p.getScore() == null) {
            p.setScore(BigDecimal.ZERO);
        }
        return mapper.insert(p);
    }
    public int update(ResearchProjects p) {
        p.setUpdatedAt(LocalDateTime.now());
        // 确保score字段不为null
        if (p.getScore() == null) {
            p.setScore(BigDecimal.ZERO);
        }
        return mapper.update(p);
    }
    public int delete(Integer id) { return mapper.delete(id); }
}
